﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Drawing;

namespace LibraryCS {
    public static class TemplatePreparation {
        public static String templateDir = "..\\..\\..\\Resources\\FontSets\\";
        public static List<VImage> templates = new List<VImage>();
        private static List<FontSet> fontSets = new List<FontSet>();

        /// <summary>
        /// 
        /// </summary>
        public static void prepareTemplates() {
            List<VImage> sets = new List<VImage>();
            // FontSets
            fontSets.Add(new FontSet("..\\..\\..\\Resources\\FontSets\\carbon.ttf", "carbon"));
            fontSets.Add(new FontSet("..\\..\\..\\Resources\\FontSets\\PAPYRUS.ttf", "papyrus"));
            fontSets.Add(new FontSet("..\\..\\..\\Resources\\FontSets\\verdanab.ttf", "verdanab"));

            foreach (FontSet fs in fontSets) {
                templates.AddRange(fs.createBitmaps());
            }
        }

        public static List<VImage> prepareTestSet(string inputPath, string outputPath) {
            // Create directories
            if (!Directory.Exists(inputPath))
                Directory.CreateDirectory(inputPath);
            if (!Directory.Exists(outputPath))
                Directory.CreateDirectory(outputPath);

            string[] testSetFiles = Directory.GetFiles(inputPath);

            List<VImage> testSet = new List<VImage>();
            // For each template file
            for (int i = 0; i < testSetFiles.Length; i++) {
                string[] split = testSetFiles[i].Split('\\');
                testSetFiles[i] = split[split.Length - 1];
                Bitmap bitmap = (Bitmap)Bitmap.FromFile(inputPath + testSetFiles[i]);

                // Process test bitmap
                VImage image = new VImage(bitmap);
                VImage croppedImage = image.BoundingCrop();
                VImage scaledImage = croppedImage.Scale(100, 150);
                scaledImage.localBitmap.Tag = "" + testSetFiles[i];
                testSet.Add(scaledImage);
                //scaledImage.localImage.Save(outputPath + testSetFiles[i]);
            }
            return testSet;
        }
    }
}
